package com.ehotting.edsta.circuitDesign.bean.request;

import com.ehotting.eaf.core.utils.StringUtils;
import com.ehotting.edsta.circuitDesign.enums.RequestArgumentEnum;
import com.ehotting.edsta.circuitDesign.enums.SignalTypeEnum;

import java.io.Serializable;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

public class RequestCodeExecute {
    
    private static List<String> argumentsList = new ArrayList();

    private Map<String,Object> data = new HashMap();

    static {
        RequestArgumentEnum[] raeArray = RequestArgumentEnum.values();
        for(RequestArgumentEnum rae: raeArray){
            argumentsList.add(rae.getCode());
        }
    }

    public  RequestCodeExecute(RequestExecute request){
        data.put(RequestArgumentEnum.BUN.getCode(),request.getBus().getCode());
        data.put(RequestArgumentEnum.VOLT.getCode(),request.getVolt().getCode());
        data.put(RequestArgumentEnum.ANALOGUE_NUM.getCode(),request.getAnaloguenum().getCode());
        data.put(RequestArgumentEnum.DIGITAL_NUM.getCode(),request.getDigitalnum().getCode());
        data.put(RequestArgumentEnum.CONTROLLER.getCode(),request.getController().getCode());
        data.put(RequestArgumentEnum.PRIOR.getCode(),request.getPrior().getCode());
        data.put(RequestArgumentEnum.POWER.getCode(),request.getPower().getCode());
        data.put(RequestArgumentEnum.QUALITY_GRADE.getCode(),request.getQualitygrade().getCode());


        if(Integer.valueOf(request.getAnaloguenum().getCode()) > 0){
            analogue = request.getAnalogue().stream().map(t->{
                AnalogueData a = new AnalogueData();
                a.setAnalogueno(Integer.parseInt(t.getAnalogueno().getCode()));
                a.setAnaloguename(t.getAnaloguename().getCode());
                a.setAnaloguetype(t.getAnaloguetype().getCode());
                a.setSample(Integer.parseInt(t.getSample().getCode()));
                a.setSignalmax(t.getSignalmax().getCode());
                a.setSignalmin(t.getSignalmin().getCode());
                a.setMaxdatarange(t.getMaxdatarange().getCode());
                a.setMindatarange(t.getMindatarange().getCode());
                a.setSamplingbit(t.getSamplingbit().getCode());
                a.setSamplinglength(t.getSamplinglength().getCode());
                return a;
            }).collect(Collectors.toList());

        }
        data.put(RequestArgumentEnum.ANALOGUE.getCode(),analogue);

        if(Integer.valueOf(request.getDigitalnum().getCode()) > 0){
            digital = request.getDigital().stream().map(t->{
                DigitalData d = new DigitalData();
                d.setDigitalno(t.getDigitalno().getCode());
                d.setDigitalname(t.getDigitalname().getCode());
                d.setIntype(t.getIntype().getCode());
                d.setInvolt(t.getInvolt().getCode());
                return d;
            }).collect(Collectors.toList());
        }
        data.put(RequestArgumentEnum.DIGITAL.getCode(),digital);
    }


    /**
     * 模块通道
     */
    private List<AnalogueData> analogue;
    /**
     * 数字通道
     */
    private List<DigitalData> digital;


    public static class AnalogueData implements Comparable<AnalogueData>, InputChannel {

        private Integer analogueno;
        private String analoguename;
        /**
         * {@link SignalTypeEnum#getCode()}
         */
        private String analoguetype;
        private Integer sample;
        private String signalmax;
        private String signalmin;
        private String maxdatarange;
        private String mindatarange;
        private String samplingbit;
        private String samplinglength;

        public AnalogueData(){

        }

        public AnalogueData(Integer analogueno,Integer sample){

            this.analogueno = analogueno;
            this.sample = sample;
        }

        public Integer getAnalogueno() {
            return analogueno;
        }

        public void setAnalogueno(Integer analogueno) {
            this.analogueno = analogueno;
        }

        public String getAnaloguename() {
            return analoguename;
        }

        public void setAnaloguename(String analoguename) {
            this.analoguename = analoguename;
        }

        public String getAnaloguetype() {
            return analoguetype;
        }

        public void setAnaloguetype(String analoguetype) {
            this.analoguetype = analoguetype;
        }

        public Integer getSample() {
            return sample;
        }

        public void setSample(Integer sample) {
            this.sample = sample;
        }

        public String getSignalmax() {
            return signalmax;
        }

        public void setSignalmax(String signalmax) {
            this.signalmax = signalmax;
        }

        public String getSignalmin() {
            return signalmin;
        }

        public void setSignalmin(String signalmin) {
            this.signalmin = signalmin;
        }

        public String getMaxdatarange() {
            return maxdatarange;
        }

        public void setMaxdatarange(String maxdatarange) {
            this.maxdatarange = maxdatarange;
        }

        public String getMindatarange() {
            return mindatarange;
        }

        public void setMindatarange(String mindatarange) {
            this.mindatarange = mindatarange;
        }

        public String getSamplingbit() {
            return samplingbit;
        }

        public void setSamplingbit(String samplingbit) {
            this.samplingbit = samplingbit;
        }

        public String getSamplinglength() {
            return samplinglength;
        }

        public void setSamplinglength(String samplinglength) {
            this.samplinglength = samplinglength;
        }

        @Override
        public int compareTo(RequestCodeExecute.AnalogueData o) {
            return this.getSample()-o.getSample();
        }

    }

    public static class DigitalData implements InputChannel{
        private String digitalno;
        private String digitalname;
        private String intype;
        private String involt;

        public String getDigitalno() {
            return digitalno;
        }

        public void setDigitalno(String digitalno) {
            this.digitalno = digitalno;
        }

        public String getDigitalname() {
            return digitalname;
        }

        public void setDigitalname(String digitalname) {
            this.digitalname = digitalname;
        }

        public String getIntype() {
            return intype;
        }

        public void setIntype(String intype) {
            this.intype = intype;
        }

        public String getInvolt() {
            return involt;
        }

        public void setInvolt(String involt) {
            this.involt = involt;
        }

    }

    public static interface InputChannel extends Serializable{

    }

    public  List<String> getArgumentsList() {
        return argumentsList;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public List<AnalogueData> getAnalogue() {
        return analogue;
    }

    public void setAnalogue(List<AnalogueData> analogue) {
        this.analogue = analogue;
    }

    public List<DigitalData> getDigital() {
        return digital;
    }

    public void setDigital(List<DigitalData> digital) {
        this.digital = digital;
    }


}
